#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int getMaxLen(vector<int>& nums) {
        int n = nums.size();
        vector<int> f(n + 1), g(n + 1);
        int mx = INT_MIN;
        for (int i = 1; i <= n; ++i)
        {
            if (nums[i - 1] > 0)
            {
                f[i] = f[i - 1] + 1;
                g[i] = g[i - 1] == 0 ? 0 : g[i - 1] + 1;
            }
            else if (nums[i - 1] < 0)
            {
                g[i] = f[i - 1] + 1;
                f[i] = g[i - 1] == 0 ? 0 : g[i - 1] + 1;
            }
            mx = max(mx, f[i]);
        }
        return mx;
    }

    int numberOfArithmeticSlices(vector<int>& nums) {
        int n = nums.size();
        vector<int> dp(n);
        int res = 0;
        for (int i = 2; i < n; ++i)
        {
            if (nums[i] - nums[i - 1] == nums[i - 1] - nums[i - 2])
                dp[i] = dp[i - 1] + 1;
            res += dp[i];
        }
        return res;
    }

    int maxTurbulenceSize(vector<int>& arr) {
        int n = arr.size();
        if (n == 1) return 1;
        vector<int> f(n, 1), g(n, 1);
        int mx = 0;
        for (int i = 1; i < n; ++i)
        {
            if (arr[i] > arr[i - 1]) g[i] = f[i - 1] + 1;
            else if (arr[i] < arr[i - 1]) f[i] = g[i - 1] + 1;
            mx = max(mx, max(f[i], g[i]));
        }
        return mx;
    }
};